home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libio / libioP.h < prev    next >
C/C++ Source or Header  |  1994-10-18  |  12KB  |  327 lines

  1. /* 
  2. Copyright (C) 1993 Free Software Foundation
  3.  
  4. This file is part of the GNU IO Library.  This library is free
  5. software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU CC; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. As a special exception, if you link this library with files
  20. compiled with a GNU compiler to produce an executable, this does not cause
  21. the resulting executable to be covered by the GNU General Public License.
  22. This exception does not however invalidate any other reasons why
  23. the executable file might be covered by the GNU General Public License. */
  24.  
  25. #include <errno.h>
  26. #ifndef errno
  27. extern int errno;
  28. #endif
  29.  
  30. #include "iolibio.h"
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. typedef enum _IO_seekflags_ {
  37.   _IO_seek_set = 0,
  38.   _IO_seek_cur = 1,
  39.   _IO_seek_end = 2,
  40.  
  41.   /* These bits are ignored unless the _IO_FILE has independent
  42.      read and write positions. */
  43.   _IO_seek_not_in = 4,    /* Don't move read posistion. */
  44.   _IO_seek_not_out = 8,    /* Don't move write posistion. */
  45.   _IO_seek_pos_ignored = 16 /* Result is ignored (except EOF) */
  46. } _IO_seekflags;
  47.  
  48. typedef int (*_IO_overflow_t) __P((_IO_FILE*, int));
  49. typedef int (*_IO_underflow_t) __P((_IO_FILE*));
  50. typedef _IO_size_t (*_IO_xsputn_t) __P((_IO_FILE*,const void*,_IO_size_t));
  51. typedef _IO_size_t (*_IO_xsgetn_t) __P((_IO_FILE*, void*, _IO_size_t));
  52. typedef _IO_ssize_t (*_IO_read_t) __P((_IO_FILE*, void*, _IO_ssize_t));
  53. typedef _IO_ssize_t (*_IO_write_t) __P((_IO_FILE*,const void*,_IO_ssize_t));
  54. typedef int (*_IO_stat_t) __P((_IO_FILE*, void*));
  55. typedef _IO_fpos_t (*_IO_seek_t) __P((_IO_FILE*, _IO_off_t, int));
  56. typedef int (*_IO_doallocate_t) __P((_IO_FILE*));
  57. typedef int (*_IO_pbackfail_t) __P((_IO_FILE*, int));
  58. typedef int (*_IO_setbuf_t) __P((_IO_FILE*, char *, _IO_ssize_t));
  59. typedef int (*_IO_sync_t) __P((_IO_FILE*));
  60. typedef void (*_IO_finish_t) __P((_IO_FILE*)); /* finalize */
  61. typedef int (*_IO_close_t) __P((_IO_FILE*)); /* finalize */
  62. typedef _IO_fpos_t (*_IO_seekoff_t) __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
  63.  
  64. /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
  65. typedef _IO_fpos_t (*_IO_seekpos_t) __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  66.  
  67. struct _IO_jump_t {
  68.     _IO_overflow_t __overflow;
  69.     _IO_underflow_t __underflow;
  70.     _IO_xsputn_t __xsputn;
  71.     _IO_xsgetn_t __xsgetn;
  72.     _IO_read_t __read;
  73.     _IO_write_t __write;
  74.     _IO_doallocate_t __doallocate;
  75.     _IO_pbackfail_t __pbackfail;
  76.     _IO_setbuf_t __setbuf;
  77.     _IO_sync_t __sync;
  78.     _IO_finish_t __finish;
  79.     _IO_close_t __close;
  80.     _IO_stat_t __stat;
  81.     _IO_seek_t __seek;
  82.     _IO_seekoff_t __seekoff;
  83.     _IO_seekpos_t __seekpos;
  84.     _IO_underflow_t __uflow;
  85. #if 0
  86.     get_column;
  87.     set_column;
  88. #endif
  89. };
  90.  
  91. /* We always allocate an extra word following an _IO_FILE.
  92.    This is for compatibility with C++ streambuf; the word can
  93.    be used to smash to a pointer to a virtual function table. */
  94.  
  95. struct _IO_FILE_plus {
  96.   _IO_FILE file;
  97.   const void *vtable;
  98. };
  99.  
  100. /* Generic functions */
  101.  
  102. extern _IO_fpos_t _IO_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
  103. extern _IO_fpos_t _IO_seekpos __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  104.  
  105. extern int _IO_switch_to_get_mode __P((_IO_FILE*));
  106. extern void _IO_init __P((_IO_FILE*, int));
  107. extern int _IO_sputbackc __P((_IO_FILE*, int));
  108. extern int _IO_sungetc __P((_IO_FILE*));
  109. extern void _IO_un_link __P((_IO_FILE*));
  110. extern void _IO_link_in __P((_IO_FILE *));
  111. extern void _IO_doallocbuf __P((_IO_FILE*));
  112. extern void _IO_unsave_markers __P((_IO_FILE*));
  113. extern void _IO_setb __P((_IO_FILE*, char*, char*, int));
  114. extern unsigned _IO_adjust_column __P((unsigned, const char *, int));
  115. #define _IO_sputn(__fp, __s, __n) (__fp->_jumps->__xsputn(__fp, __s, __n))
  116.  
  117. /* Marker-related function. */
  118.  
  119. extern void _IO_init_marker __P((struct _IO_marker *, _IO_FILE *));
  120. extern void _IO_remove_marker __P((struct _IO_marker*));
  121. extern int _IO_marker_difference __P((struct _IO_marker *, struct _IO_marker *));
  122. extern int _IO_marker_delta __P((struct _IO_marker *));
  123. extern int _IO_seekmark __P((_IO_FILE *, struct _IO_marker *, int));
  124.  
  125. /* Default jumptable functions. */
  126.  
  127. extern int _IO_default_underflow __P((_IO_FILE*));
  128. extern int _IO_default_uflow _PARAMS((_IO_FILE*));
  129. extern int _IO_default_doallocate __P((_IO_FILE*));
  130. extern void _IO_default_finish __P((_IO_FILE *));
  131. extern int _IO_default_pbackfail __P((_IO_FILE*, int));
  132. extern int _IO_default_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
  133. extern _IO_size_t _IO_default_xsputn __P((_IO_FILE *, const void*, _IO_size_t));
  134. extern _IO_size_t _IO_default_xsgetn __P((_IO_FILE *, void*, _IO_size_t));
  135. extern _IO_fpos_t _IO_default_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
  136. extern _IO_fpos_t _IO_default_seekpos __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  137. extern _IO_ssize_t _IO_default_write __P((_IO_FILE*,const void*,_IO_ssize_t));
  138. extern _IO_ssize_t _IO_default_read __P((_IO_FILE*, void*, _IO_ssize_t));
  139. extern int _IO_default_stat __P((_IO_FILE*, void*));
  140. extern _IO_fpos_t _IO_default_seek __P((_IO_FILE*, _IO_off_t, int));
  141. extern int _IO_default_sync __P((_IO_FILE*));
  142. #define _IO_default_close ((_IO_close_t)_IO_default_sync)
  143.  
  144. extern struct _IO_jump_t _IO_file_jumps;
  145. extern struct _IO_jump_t _IO_streambuf_jumps;
  146. extern struct _IO_jump_t _IO_proc_jumps;
  147. extern struct _IO_jump_t _IO_str_jumps;
  148. extern int _IO_do_write __P((_IO_FILE*, const char*, _IO_size_t));
  149. extern int _IO_flush_all __P((void));
  150. extern void _IO_cleanup __P((void));
  151. extern void _IO_flush_all_linebuffered __P((void));
  152.  
  153. #define _IO_do_flush(_f) \
  154.   _IO_do_write(_f, (_f)->_IO_write_base, \
  155.            (_f)->_IO_write_ptr-(_f)->_IO_write_base)
  156. #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
  157. #define _IO_mask_flags(fp, f, mask) \
  158.        ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
  159. #define _IO_setg(fp, eb, g, eg)  ((fp)->_IO_read_base = (eb),\
  160.     (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
  161. #define _IO_setp(__fp, __p, __ep) \
  162.        ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr = __p, (__fp)->_IO_write_end = (__ep))
  163. #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
  164. #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
  165. #define _IO_have_markers(fp) ((fp)->_markers != NULL)
  166. #define _IO_blen(p) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
  167.  
  168. /* Jumptable functions for files. */
  169.  
  170. extern int _IO_file_doallocate __P((_IO_FILE*));
  171. extern int _IO_file_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
  172. extern _IO_fpos_t _IO_file_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
  173. extern _IO_size_t _IO_file_xsputn __P((_IO_FILE*,const void*,_IO_size_t));
  174. extern int _IO_file_stat __P((_IO_FILE*, void*));
  175. extern int _IO_file_close __P((_IO_FILE*));
  176. extern int _IO_file_underflow __P((_IO_FILE *));
  177. extern int _IO_file_overflow __P((_IO_FILE *, int));
  178. #define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
  179. extern void _IO_file_init __P((_IO_FILE*));
  180. extern _IO_FILE* _IO_file_attach __P((_IO_FILE*, int));
  181. extern _IO_FILE* _IO_file_fopen __P((_IO_FILE*, const char*, const char*));
  182. extern _IO_ssize_t _IO_file_write __P((_IO_FILE*,const void*,_IO_ssize_t));
  183. extern _IO_ssize_t _IO_file_read __P((_IO_FILE*, void*, _IO_ssize_t));
  184. extern int _IO_file_sync __P((_IO_FILE*));
  185. extern int _IO_file_close_it __P((_IO_FILE*));
  186. extern _IO_fpos_t _IO_file_seek __P((_IO_FILE *, _IO_off_t, int));
  187. extern void _IO_file_finish __P((_IO_FILE*));
  188.  
  189. /* Other file functions. */
  190. extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int));
  191.  
  192. /* Jumptable functions for proc_files. */
  193. extern _IO_FILE* _IO_proc_open __P((_IO_FILE*, const char*, const char *));
  194. extern int _IO_proc_close __P((_IO_FILE*));
  195.  
  196. /* Jumptable functions for strfiles. */
  197. extern int _IO_str_underflow __P((_IO_FILE*));
  198. extern int _IO_str_overflow __P((_IO_FILE *, int));
  199. extern int _IO_str_pbackfail __P((_IO_FILE*, int));
  200. extern _IO_fpos_t _IO_str_seekoff __P((_IO_FILE*,_IO_off_t,_IO_seekflags));
  201.  
  202. /* Other strfile functions */
  203. extern void _IO_str_init_static __P((_IO_FILE *, char*, int, char*));
  204. extern void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
  205. extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*));
  206.  
  207. extern _IO_size_t _IO_getline __P((_IO_FILE*,char*,_IO_size_t,int,int));
  208. extern _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
  209. extern double _IO_strtod __P((const char *, char **));
  210. extern char * _IO_dtoa __P((double __d, int __mode, int __ndigits,
  211.                 int *__decpt, int *__sign, char **__rve));
  212. extern int _IO_outfloat __P((double __value, _IO_FILE *__sb, int __type,
  213.                  int __width, int __precision, int __flags,
  214.                  int __sign_mode, int __fill));
  215.  
  216. extern _IO_FILE *_IO_list_all;
  217. extern void (*_IO_cleanup_registration_needed) __P ((void));
  218.  
  219. #ifndef EOF
  220. #define EOF (-1)
  221. #endif
  222. #ifndef NULL
  223. #if !defined(__cplusplus) || defined(__GNUC__)
  224. #define NULL ((void*)0)
  225. #else
  226. #define NULL (0)
  227. #endif
  228. #endif
  229.  
  230. #define FREE_BUF(_B) free(_B)
  231. #define ALLOC_BUF(_S) (char*)malloc(_S)
  232.  
  233. #ifndef OS_FSTAT
  234. #define OS_FSTAT fstat
  235. #endif
  236. struct stat;
  237. extern _IO_ssize_t _IO_read __P((int, void*, _IO_size_t));
  238. extern _IO_ssize_t _IO_write __P((int, const void*, _IO_size_t));
  239. extern _IO_off_t _IO_lseek __P((int, _IO_off_t, int));
  240. extern int _IO_close __P((int));
  241. extern int _IO_fstat __P((int, struct stat *));
  242.  
  243. /* Operations on _IO_fpos_t.
  244.    Normally, these are trivial, but we provide hooks for configurations
  245.    where an _IO_fpos_t is a struct.
  246.    Note that _IO_off_t must be an integral type. */
  247.  
  248. /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
  249. #ifndef _IO_pos_BAD
  250. #define _IO_pos_BAD ((_IO_fpos_t)(-1))
  251. #endif
  252. /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
  253. #ifndef _IO_pos_as_off
  254. #define _IO_pos_as_off(__pos) ((_IO_off_t)(__pos))
  255. #endif
  256. /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
  257. #ifndef _IO_pos_adjust
  258. #define _IO_pos_adjust(__pos, __delta) ((__pos) += (__delta))
  259. #endif
  260. /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
  261. #ifndef _IO_pos_0
  262. #define _IO_pos_0 ((_IO_fpos_t)0)
  263. #endif
  264.  
  265. #ifdef __cplusplus
  266. }
  267. #endif
  268.  
  269. /* check following! */
  270. #define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
  271.        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
  272.          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, &_IO_file_jumps, FD}
  273.  
  274. /* Define builtinbuf_vtable as a name for the virtual function table
  275.    of the builtinbuf class. */
  276. #if !defined(builtinbuf_vtable) && defined(__cplusplus)
  277. #ifdef __GNUC__
  278. extern char builtinbuf_vtable[]
  279.   asm (_G_VTABLE_LABEL_PREFIX
  280. #if _G_VTABLE_LABEL_HAS_LENGTH
  281.        "10"
  282. #endif
  283.        "builtinbuf");
  284. #else /* !__GNUC__ */
  285. #if _G_VTABLE_LABEL_HAS_LENGTH
  286. #define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
  287. #else
  288. #define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
  289. #endif
  290. extern char builtinbuf_vtable[];
  291. #endif /* !__GNUC__ */
  292. #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
  293.  
  294. #if defined(__STDC__) || defined(__cplusplus)
  295. #define _IO_va_start(args, last) va_start(args, last)
  296. #else
  297. #define _IO_va_start(args, last) va_start(args)
  298. #endif
  299.  
  300. extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
  301.  
  302. #if 1
  303. #define COERCE_FILE(FILE) /* Nothing */
  304. #else
  305. /* This is part of the kludge for binary compatibility with old stdio. */
  306. #define COERCE_FILE(FILE) \
  307.   (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
  308.     && (FILE) = *(FILE**)&((int*)fp)[1])
  309. #endif
  310.  
  311. #ifdef EINVAL
  312. #define MAYBE_SET_EINVAL errno = EINVAL
  313. #else
  314. #define MAYBE_SET_EINVAL /* nothing */
  315. #endif
  316.  
  317. #ifdef DEBUG
  318. #define CHECK_FILE(FILE,RET) \
  319.     if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
  320.     else { COERCE_FILE(FILE); \
  321.            if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
  322.       { errno = EINVAL; return RET; }}
  323. #else
  324. #define CHECK_FILE(FILE,RET) \
  325.     COERCE_FILE(FILE)
  326. #endif
  327.